class Solution {
public:
    int memo[26]{};
    bool checkInclusion(string s1, string s2) {
        for (char c : s1) memo[convert(c)]++;
        int count = 0;
        for (int i = 0; i < 26; i++) count += bool(memo[i]);
        int j = 0;
        for (int i = 0; i < s2.size(); i++)
        {
            // cout<<i<<endl<<j<<endl<<endl;
            if(!count) return true;
                // cout<<"zzzzz"<<s2[i]<<endl<<memo[convert(s2[i])]<<"zzzzzz";
            if(!memo[convert(s2[i])])
            {
                // cout<<"j要动了"<<endl;
                while(s2[j] != s2[i]) 
                {
                    if (memo[convert(s2[j])]++ == 0) //一开始差了这个count++
                        count++;
                    j++;
                }
                j++;
            }
            else
            {
                memo[convert(s2[i])]--;
                if(!memo[convert(s2[i])]) count--;
            }
        }
        if(!count) return true;
        return false;
    }
    int convert(char c) {
        return c - 'a';
    }
};
